package com.qst.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.beans.PageUtils;
import com.qst.beans.Product;
import com.qst.dao.ProductMapper;
import com.qst.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductServiceImpl implements ProductService
{
    @Autowired
    private ProductMapper mapper;
    @Override
    public List<Product> findAllByHot() {
        return mapper.findAllByHot();
    }

    @Override
    public List<Product> findByNew() {
        return mapper.findByNew();
    }

    @Override
    public Product findById(Integer id) {
        return mapper.findById(id);
    }

    @Override
    public List<Product> findAll() {
        return mapper.findAll();
    }

    @Override
    public int save(Product product) {
        return mapper.save(product);
    }

    @Override
    public int deleteByid(Integer id) {
        return mapper.deleteByid(id);
    }

    @Override
    public int update(Product product) {
        return mapper.update(product);
    }


    @Override
    public PageUtils<Product> getProductsMH(Integer page,String pName) {
        PageUtils<Product> utils = new PageUtils<>();
        PageHelper.startPage(page,8);
        List<Product> productList = mapper.getProductsMH(pName);
        for (Product pro:productList
             ) {
            System.out.println(pro);
        }
        PageInfo<Product> pageInfo = new PageInfo(productList);
        utils.setPage(page);
        utils.setList(productList);
        utils.setTotalPage(pageInfo.getPages());


        return utils;
    }

    @Override
    public List<Product> recomendProduct(Integer uid) {
        return mapper.recomendProduct(uid);
    }
}
